<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#div1 {width:100px; height:150px; background:red; position:absolute; left:1000px;}
#div2 {width:1px; height:300px; background:red; position:absolute; left:100px;}
#div3 {width:1px; height:300px; background:red; position:absolute; left:300px;}
</style>
<script>
var timer=null;
function startMove(iTarget)
{
	var oDiv=document.getElementById('div1');
	
	clearInterval(timer);
	timer=setInterval(function(){
		var speed=0;
		if(oDiv.offsetLeft<iTarget)
		{
			speed=7;
		}
		else
		{
			speed=-7;
		}
		
		if(Math.abs(iTarget-oDiv.offsetLeft)<=7)
		{
			clearInterval(timer);
			oDiv.style.left=iTarget+'px';
		}
		else
		{
			oDiv.style.left=oDiv.offsetLeft+speed+'px';
		}
		},30);
}
</script>
</head>

<body>
<input type="button" value="到100" onclick="startMove(100)"/>
<input type="button" value="到300" onclick="startMove(300)"/>
<div id="div1">
</div>
<div id="div2">
</div>
<div id="div3">
</div>
</body>
</html>
